# -- coding: utf-8 --
from .command import Command
import os
import sys

class CpCommand(Command):
    def __init__(self,args):
        Command.__init__(self,args)

    def usage(self):
        print("cp src dst  - copy file")

    def execute(self):
        if len(self.args) != 3:
            self.usage()
            return

        sourcePath = self.args[1]
        targetPath = self.args[2]
        try:
            sourceFd = open(sourcePath,'r')
            targetFd = open(targetPath,'a')
            for line in sourceFd:
                targetFd.write(line)

        except IOError as e:
            print(e)

        finally:
            sourceFd.close()
            targetFd.close()
